
<style>
    .checkboxList #Post_page input { width: 1% !important; display: inline; }
    .checkboxList #Post_page label { display: inline; }
</style>
<div class="form">

<?php $form = $this->beginWidget('CActiveForm', array(
    'id'                   => 'post-form',
    'enableClientValidation' => true,
        'enableAjaxValidation'   => true,
        'clientOptions'          => array(
            'validateOnSubmit' => true,
        ),
        'htmlOptions'            => array(
            'enctype' => 'multipart/form-data'
        ),
    )); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>
    
    <div class="row">
        <?php echo $form->labelEx($model, 'title'); ?>
        <?php echo $form->textField($model, 'title', array('class' => 'text-input medium-input')); ?>
        <?php echo $form->error($model, 'title'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'alias'); ?>
        <?php echo $form->textField($model, 'alias', array('class' => 'text-input medium-input')); ?>
        <?php echo $form->error($model, 'alias'); ?>
    </div>

	<div class="row">
		<?php echo $form->labelEx($model, 'info'); ?>
        <?php echo $form->textArea($model, 'info', array('rows' => 6, 'cols' => 50)); ?>
        <?php echo $form->error($model, 'info'); ?>
	</div>

    <div class="row tinymce">
        <?php echo $form->labelEx($model, 'content'); ?>
        <?php
        $this->widget('ext.tinymce.TinyMce', array(
            'model' => $model,
            'attribute' => 'content',
            // Optional config
            'compressorRoute' => false,
            'spellcheckerRoute' => 'tinyMce/spellchecker',
            'fileManager' => array(
                'class' => 'ext.elFinder.TinyMceElFinder',
                'connectorRoute'=>'elfinder/connector',
            ),
            'htmlOptions' => array(
                'rows' => 6,
                'cols' => 60,
            ),
        ));
        ?>
        <?php echo $form->error($model, 'content'); ?>
    </div>

    <div class="row">
        <label></label>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'image'); ?>
        <?php echo $form->hiddenField($model, "image"); ?>
        <?php $this->widget('CMultiFileUpload', array(
            'name'      => 'image',
            'accept'    => 'jpeg|jpg|gif|png', // useful for verifying files
            'duplicate' => 'Duplicate file!', // useful, i think
            'denied'    => 'Invalid file type',
            // useful, i think
        ));
        echo $form->error($model, 'image');

        if ($model->image):
            $image = explode(',', $model->image);
            foreach ($image as $k => $file):
                ?>
                <div class="clearfix"></div>
                <span><?php echo $file; ?> &nbsp;
                <a href="javascript:;" onclick="javascript:removeFile('<?php echo $file; ?>', <?php echo $k; ?>)" title="Remove"
                   class="remove_<?php echo $k; ?>">Remove File</a></span>
                <div class="clearfix"></div>
            <?php
            endforeach;
        endif;?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'tags'); ?>
        <?php $this->widget('CAutoComplete', array(
            'model'       => $model,
            'attribute'   => 'tags',
            'url'         => array('suggestTags'),
            'multiple'    => true,
            'htmlOptions' => array(
                'class' => 'text-input medium-input'
            ),
        )); ?>
        <p class="hint">Please separate different tags with commas.</p>
        <?php echo $form->error($model, 'tags'); ?>
    </div>

   	<div class="row">
   		<?php echo $form->labelEx($model, 'priority'); ?>
        <?php echo $form->textField($model, 'priority', array('class' => 'text-input small-input')); ?>
        <?php echo $form->error($model, 'priority'); ?>
   	</div>

    <div class="row">
        <?php echo $form->labelEx($model, 'publish_date'); ?>
        <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'model'       => $model,
            'attribute'   => 'publish_date',
            // additional javascript options for the date picker plugin
            'options'     => array(
                'changeMonth' => true,
                'changeYear'  => true,
                'showAnim'    => 'fold',
                'dateFormat'  => 'mm-dd-yy',
                'minDate'     => '0',
                'onSelect'    => "js:function() {}",
            ),
            'htmlOptions' => array(
                'class' => 'text-input small-input'
            ),
        )); ?>
        <?php echo $form->error($model, 'publish_date'); ?>
    </div>

    <div class="row checkboxList">
        <?php echo $form->labelEx($model, 'page'); ?>
        <?php echo $form->checkBoxList($model, 'page', Lookup::items('Display_On_Page'), array('class' => 'text-input small-input')); ?>
        <?php echo $form->error($model, 'page'); ?>
    </div>

    <?php if (!$model->isNewRecord) { ?>
        <div class="row">
            <?php echo $form->labelEx($model, 'status'); ?>
            <?php echo $form->dropDownList($model, 'status', Lookup::items('Status'), array('class' => 'text-input smaill-input')); ?>
            <?php echo $form->error($model, 'status'); ?>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model, 'create_date'); ?>
            <?php echo $model->create_date; ?>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model, 'update_date'); ?>
            <?php echo Helper::getTimeAgo($model->update_date); ?>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model, 'ordering'); ?>
            <?php echo $form->textField($model, 'ordering', array('class' => 'text-input small-input')); ?>
            <?php echo $form->error($model, 'ordering'); ?>
        </div>
        <!--<div class="row">
            <?php /*echo $form->labelEx($model, 'user_id'); */?>
            <?php /*echo $form->textField($model, 'user_id'); */?>
            <?php /*echo $form->error($model, 'user_id'); */?>
        </div>
        <div class="row">
            <?php /*echo $form->labelEx($model, 'owner_id'); */?>
            <?php /*echo $form->textField($model, 'owner_id'); */?>
            <?php /*echo $form->error($model, 'owner_id'); */?>
        </div>-->
    <?php } ?>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

    <?php $this->endWidget(); ?>
</div><!-- form -->


<?php
$scriptDelete = '
if("' . $model->image . '" != ""){
    function removeFile(fileName, pos) {
        var url = "' . Helper::url('/Admin/default/deleteimage') . '";
        var imageID = "' . $model->id . '";
        var modelName = "' . ucfirst(Yii::app()->controller->id) .'";

        $.post(
            url, { imageID: imageID, imageName: fileName, model: modelName },
            function(data){
                $("a.remove_"+pos).parent().html(data + ". Please refresh page after deleting no more.");
                parent.window.location = parent.window.location
            }, "json"
        );

        return false;
    }
}
';
Helper::cs()->registerScript('scriptDelete', $scriptDelete, CClientScript::POS_END);